<?php

# 
# Copyright (c) 2002-2007 Eric Wallengren
# This file is part of the Continuous Automated Build and Integration 
# Environment (CABIE)
# 
# CABIE is distributed under the terms of the GNU General Public
# License version 2 or any later version.  See the file COPYING for copying 
# permission or http://www.gnu.org. 
#                                                                            
# THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED OR  
# IMPLIED, without even the implied warranty of MERCHANTABILITY or FITNESS 
# FOR A PARTICULAR PURPOSE.  ANY USE IS AT YOUR OWN RISK. 
#                                                                            
# Permission to modify the code and to distribute modified code is granted, 
# provided the above notices are retained, and a notice that the code was 
# modified is included with the above copyright notice. 
# 

    require_once('auth.php');

    _displayheader($randomimages);

?>

<?php 

    require_once("defs.php");
    require_once("dbdefs.php");
    require_once('xmlrpc.inc');

    $SQL = new sqlfuncs();
    $SQL->__construct($server, $username, $password, $database);

    # _debug(print_r($_COOKIE));

    foreach ($_REQUEST as $key => $value) {
        switch ($key) {

            case "server":
                $buildserver = $value;
                break;
            
            case "action":

                if (_isEqual($value, "view")) {
                    $action = 1;
                }
                if (_isEqual($value, "editjob")) {
                    $action = 2;
                }
               
                break;

            case "jobname":
                $jobname = $value;
                break;

        }
    }
    
    $sqlarray = _getactiveservers($SQL, 1);

    _displayactiveservers($sqlarray, $buildserver);

    $sqlarray = _getactivejobs($SQL, $buildserver);

    $isie = _isie();

    if ($action == 1) {

        _servermenu($SQL, $buildserver);

        echo "<tbody id='server_info' length='0'>\n".
             "</tbody>\n";

        foreach ($sqlarray as $rec) {

            $colspan = 8;
    
            $runninginfo = _getrunningclass($SQL, $buildserver, $rec);

            _jobmenu($SQL, $buildserver, $rec, $runninginfo, $colspan);

            $tableid = $rec.'_id';

            echo "<tbody class='collapse_obj' id='$tableid' server=".
                 "'$buildserver' jobname='$rec' length='0'>\n";

            # echo $html;

            echo "</tbody>\n";


        }

    }

    echo "</tbody>\n".
         "</table>\n";
    if (!$isie) { 
        echo "</div>\n";
    }

    if (isset($_REQUEST['recs'])) {
        $toshow = $_REQUEST['recs'];
    } else {
        $toshow = 10;
    }

    echo "<br>\n".
         "<form action=''>\n".
         "<legend>expanded builds</legend>\n".
         "<input type='text' id='toshow' maxlength=4 size=4 value=$toshow />\n".
         "</form>\n";

?>

<?php
    /*
    echo "<div id=\"message\"></div>";
    $mem = memory_get_usage();
    $usage = sprintf("%d", $mem/1024);
    echo "<p>memory used: ".$usage."k</p>\n";
    */
?>
<div id=state pagestate=''></div>
</body>
</html>

<?php
    exit;
?>
